package jnpf.base.model.dbtable.vo;

import io.swagger.annotations.ApiModelProperty;
import jnpf.database.datatype.viewshow.constant.DtViewConst;
import jnpf.database.enums.DbAliasEnum;
import jnpf.database.model.dbfield.DbFieldModel;
import jnpf.util.StringUtil;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 *
 * @author JNPF开发平台组
 * @version V3.1.0
 * @copyright 引迈信息技术有限公司
 * @date 2021/3/12 15:31
 */
@Data
@NoArgsConstructor
public class DbFieldVO {

    @ApiModelProperty(value = "字段名")
    private String field;
    @ApiModelProperty(value = "字段说明")
    private String fieldName;
    @ApiModelProperty(value = "数据类型")
    private String dataType;
    @ApiModelProperty(value = "数据长度")
    private String dataLength;
    @ApiModelProperty(value = "主键")
    private Integer primaryKey;
    @ApiModelProperty(value = "允许空")
    private Integer allowNull;

    public DbFieldVO(DbFieldModel dbFieldModel){
        this.field = dbFieldModel.getField();
        this.fieldName = dbFieldModel.getComment();
        this.dataType = dbFieldModel.getDataType();
        this.dataLength = StringUtil.isNotEmpty(dbFieldModel.getLength()) ? dbFieldModel.getLength() : DtViewConst.DEFAULT;;
        this.primaryKey = dbFieldModel.getIsPrimaryKey() ? 1 : 0;
        this.allowNull =(DbAliasEnum.ALLOW_NULL.getNum(dbFieldModel.getNullSign()));
    }

}
